<template>
  <div>
    <!-- title="滑块验证码" -->
    <el-dialog
        :visible.sync="dialogVisible"
        :before-close="dialogBeforeClose"
        :close-on-click-modal="false"
    >
      <div class="flex">
        <slide-verify
            ref="slideblock"
            :w="fullWidth"
            :h="fullHeight"
            :accuracy="accuracy"
            :slider-text="text"
            :imgs="imgList"
            @again="onAgain"
            @fulfilled="onFulfilled"
            @success="onSuccess"
            @fail="onFail"
            @refresh="onRefresh"
        />
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'verify',
  data() {
    return {
      dialogVisible: false,
      fullWidth: 450,
      fullHeight: 304,
      msg: '',
      text: '请向右滑动滑块完成验证',
      // 精确度小，可允许的误差范围小；为1时，则表示滑块要与凹槽完全重叠，才能验证成功。默认值为5
      accuracy: 3,
      imgList: [
        // 图片的路径：
        require('../../assets/logo.png')
      ]
    }
  },

  mounted() {},

  methods: {
    dialogBeforeClose() {
      this.dialogVisible = false
    },
    onSuccess() {
      console.log('验证通过')
      this.msg = 'login success'
      this.dialogVisible = false
      this.$emit('verifySuccess')
      this.$message.success("验证成功")
      // 路由跳转指定页面
      this.$router.push('/home')
    },
    onFail() {
      console.log('验证不通过')
      this.msg = '验证不通过'
      this.$message.error('验证失败')
    },
    onRefresh() {
      console.log('点击了刷新小图标')
      this.msg = '刷新成功'
    },
    onFulfilled() {
      console.log('刷新成功啦！')
    },
    onAgain() {
      console.log('检测到非人为操作的哦！')
      this.msg = 'try again'
      // 刷新
      this.$refs.slideblock.reset()
    },
    handleClick() {
      // 父组件直接可以调用刷新方法
      this.$refs.slideblock.reset()
    }
  }
}
</script>

<style lang="scss" scoped>
.flex{
  display: flex;
  align-items: center;
  justify-content: center;
}
/deep/ .el-dialog {
  width: 500px;
  border-radius: 16px;
  margin: auto;
}
/deep/ .el-dialog__header {
  display: none;
}
/deep/ .slide-verify-slider {
  border-radius: 33px;
}
/deep/ .slide-verify-slider-mask {
  border-radius: 33px 0 0 33px;
}
</style>
